package com.qing.expert.common.response;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 统一响应类
 */
@Data
@Accessors(chain = true)
public class R<T> {
    private Integer code;
    private String message;
    private T data;

    private R() {
    }

    public static <T> R<T> ok() {
        return ok(null);
    }

    public static <T> R<T> ok(T data) {
        return new R<T>()
                .setCode(200)
                .setMessage("成功")
                .setData(data);
    }

    public static <T> R<T> error(String message) {
        return new R<T>()
                .setCode(500)
                .setMessage(message);
    }

    public static <T> R<T> error(Integer code, String message) {
        return new R<T>()
                .setCode(code)
                .setMessage(message);
    }
}